#!/bin/bash

test1=test1
test2=test2
test3=test3

#display logic cpu numbers 
cpu_num=`cat /proc/cpuinfo|grep "processor"|wc -l`
echo "numbers of logic cpu is $cpu_num"

test1_pid=`ps -eo pid,args,psr | grep $test1 |head -n 1|awk '{ print $1}'`
test2_pid=`ps -eo pid,args,psr | grep $test2 |head -n 1|awk '{ print $1}'`
test3_pid=`ps -eo pid,args,psr | grep $test3 |head -n 1|awk '{ print $1}'`
#display which test program running on which cpu core
display() {
	for ((i=0;i<10;i++));do
	core1=`ps -eo pid,args,psr | grep $test1 |head -n 1|awk '{ print $3}'`
	core2=`ps -eo pid,args,psr | grep $test2 |head -n 1|awk '{ print $3}'`
	core3=`ps -eo pid,args,psr | grep $test3 |head -n 1|awk '{ print $3}'`
	echo "the test program is running on cpu $core1  $core2  $core3"
done
}

display
#set cpu affinity for each test program
taskset -cp 1 $test1_pid
taskset -cp 1 $test2_pid
taskset -cp 1 $test3_pid
display
kill -9 $test1_pid
kill -9 $test2_pid
kill -9 $test3_pid

